package com.tim.stack.impl;

import java.util.LinkedList;
import java.util.List;

import com.tim.stack.IStack;

public class Stack<T> implements IStack<T> {

	private List<T> stack = new LinkedList<T>();

	public Stack() {
	}

	public void push(T val) {
		this.stack.add(val);
		System.out.println("*** [" + val
				+ "] has been successfully pushed to stack ***");
	}

	public T pop() {
		if (this.stack.size() > 0) {
			T val = this.stack.get(this.stack.size() - 1);
			this.stack.remove(this.stack.size() - 1);
			System.out.println("*** [" + val
					+ "] has been successfully taken from stack ***");
			return val;
		}
		System.out.println("*** There is no items in the stack ***");
		return null;
	}

	@Override
	public void print() {
		System.out.println(this);
	}

	@Override
	public String toString() {
		return this.stack.toString();
	}
}
